import { http } from "@/utils/http";
import { baseAdminURLApi, type PageResult } from "../utils";

interface OptionsVO {
  id: number;
  value: string;
}
// 获取角色下拉列表
export const getRoleOption = () => {
  return http.request<OptionsVO[]>("get", baseAdminURLApi("/roles/options"));
};
interface RolesVO {
  id: number;
  name: string;
  code: string;
  status: number;
  remark: string;
  createTime: Date;
}
// 查询角色列表
export const getRoleList = (data?: object) => {
  return http.request<PageResult<RolesVO>>("get", baseAdminURLApi("/roles"), {
    params: data
  });
};
interface RoleForm {
  id?: number;
  name: string;
  code: string;
  remark: string;
}
// 新增角色
export const addRole = (data?: RoleForm) => {
  return http.request<boolean>("post", baseAdminURLApi("/roles"), {
    data
  });
};
// 修改角色信息
export const updateRole = (id: number, data?: RoleForm) => {
  return http.request<boolean>("put", baseAdminURLApi(`/roles/${id}`), {
    data
  });
};
// 获取角色菜单权限     根据角色 id 查对应菜单及权限
export const getRoleMenuById = (id?: number) => {
  return http.request<Array<number>>(
    "get",
    baseAdminURLApi(`/roles/${id}/menus`)
  );
};
// 修改角色权限      通过角色id修改角色权限
export const updateRoleMenu = (id: number, menuIds?: Array<number>) => {
  return http.request<boolean>("put", baseAdminURLApi(`/roles/${id}/menus`), {
    data: menuIds
  });
};

// 删除角色信息
export const delRoleById = (id?: number) => {
  return http.request<boolean>("delete", baseAdminURLApi(`/roles/${id}`));
};
